package com.itms.boot;

import java.util.concurrent.CountDownLatch;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.google.common.util.concurrent.AbstractIdleService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Bootstrap extends AbstractIdleService{
	
	
	private ClassPathXmlApplicationContext context;
	
	private static CountDownLatch cdl = new CountDownLatch(1);
	
	public static void main(String[] args) {
//		ClassPathXmlApplicationContext context = 
//				new ClassPathXmlApplicationContext("spring/spring-common.xml");
//		context.start();
		Bootstrap bs = new Bootstrap();
		bs.startAsync();
		
		try {
			cdl.await();
		} catch (Exception e) {
			log.error("ignore interuption");
		}
	}
	

	@Override
	protected void startUp() throws Exception {
		log.info(">>>>>>>>>>>>>>>>>>itms-job  start<<<<<<<<<<<<<<<<<<<<<<<<<<");
		try {
			
			System.setProperty("duboo.application.logger", "slf4j");
			
			context = new ClassPathXmlApplicationContext(new String[]{"spring/spring-common.xml"});
			context.start();
			context.registerShutdownHook();
			
			log.info(">>>>>>>>>itms-job started SUCCESS<<<<<<<<<");
			
		} catch (Exception e) {
			log.error(">>>>>>>>>>>>>>>>>>itms-job error,data:{}<<<<<<<<<<<<<<<<<<<<<<<<<<",e);
		}
		
	}
	
	@Override
	protected void shutDown() throws Exception {
		context.stop();
		log.info(">>>>>>>>>itms-job stopped SUCCESS<<<<<<<<<");
	}

}
